//
//  TwoViewController.m
//  UI通讯录
//
//  Created by ZF on 16/5/31.
//  Copyright © 2016年 ZF. All rights reserved.
//

#import "TwoViewController.h"
#import "ViewController.h"
#import "Linkman.h"
@interface TwoViewController ()
{
    NSString *str;
}
@end

@implementation TwoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   self.navigationItem.title = self.man.name;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    [btn setTitle:@"短信" forState:UIControlStateNormal];
    //[btn setTitle:@"按下" forState:UIControlStateHighlighted];
    [btn setTintColor:[UIColor blueColor]];
    //[btn sizeToFit];
    
    btn.frame = CGRectMake(btn.frame.size.width/2 + 16, 246, 100, 88);
    //btn.center = CGPointMake(btn.frame.size.width/2 + 16, 246);
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = [UIColor blueColor].CGColor;
    btn.layer.backgroundColor = [UIColor yellowColor].CGColor;
    btn.layer.cornerRadius = 8;
    
    [btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self action:@selector(onClick1:) forControlEvents:UIControlEventTouchDown];
    [self.view addSubview:btn];
    
    
    
    UILabel *l = [[UILabel alloc] init];
    l.text = self.man.name;
    //[l sizeToFit];
    l.frame = CGRectMake(0, 0, 300, 50);
    l.layer.borderWidth = 1;
    l.tag = 120;
    l.center = CGPointMake(self.view.frame.size.width/2, 150 - 16 - l.frame.size.height/2);
    [self.view addSubview:l];
    
    
    
    
    UISwitch *swi = [[UISwitch alloc] init];
    [swi sizeToFit];
    swi.center = CGPointMake(self.view.frame.size.width - swi.frame.size.width/2 - 16, 400);
    [swi addTarget:self action:@selector(onSwitch:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:swi];
    
    
    
    
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"左对齐",@"居中",@"右对齐"]];
    seg.tintColor = [UIColor whiteColor];
    seg.layer.cornerRadius = 8;
    seg.frame = CGRectMake(0, 0, 150, 44);
    seg.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height - seg.frame.size.height - 100);
    [seg addTarget:self action:@selector(onSegmentedCon:) forControlEvents:UIControlEventValueChanged];
    seg.backgroundColor = [UIColor grayColor];
    [self.view addSubview:seg];
}

- (void)onSegmentedCon:(UISegmentedControl *)seg
{
    UILabel *lab = (UILabel *)[self.view viewWithTag:120];
    if(seg.selectedSegmentIndex == 0)
    {
        lab.textAlignment = NSTextAlignmentLeft;
        
    }
    else if(seg.selectedSegmentIndex == 1)
    {
        lab.textAlignment = NSTextAlignmentCenter;
    }
    else
    {
        lab.textAlignment = NSTextAlignmentRight;
    }
}


- (void)onSwitch:(UISwitch *)swi
{
    UILabel *lab = (UILabel *)[self.view viewWithTag:120];
    if(swi.isOn)
    {
        lab.layer.borderWidth = 1;
    }
    else
    {
        lab.layer.borderWidth = 0;
    }
}

- (void)onClick:(UIButton *)sender
{
    sender.layer.backgroundColor = [UIColor yellowColor].CGColor;
}

- (void)onClick1:(UIButton *)sender2
{
    sender2.layer.backgroundColor = [UIColor grayColor].CGColor;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    if(indexPath.row == 0)
    {
        cell.imageView.image = [UIImage imageNamed:@"my"];
        cell.imageView.layer.cornerRadius = 50;
        
        cell.textLabel.text = self.man.name;
        cell.textLabel.textColor = [UIColor blackColor];
        cell.textLabel.font = [UIFont systemFontOfSize:30];
        cell.textLabel.highlightedTextColor = [UIColor grayColor];
        cell.backgroundColor = [UIColor orangeColor];
        
      //  cell.detailTextLabel.tintColor = [UIColor blackColor];
        
    }
    
    else {
        cell.textLabel.text = @"电话:";
        cell.detailTextLabel.text = self.man.telphone;
        cell.detailTextLabel.font = [UIFont systemFontOfSize:18];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return 150;
    }
    return 44;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
